package pages;
import core.TestBase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import utils.Log4Test;
import java.util.concurrent.TimeUnit;
/**
 * Created by Nicktoris on 22.07.2014.
 */
public class AppleBooksPage extends TestBase
{
    private void clickSortLink()
    {
        Log4Test.info("Click on sorting link to show available options of sorting...");
        targetElement = webDriver.findElement(By.xpath("//*[@id='sort_view']/a"));
        targetElement.click();
    }

    public void selectFromExpenToCheap()

    {
        clickSortLink();
        Log4Test.info("Select From Expensive To Cheaper");
        targetElement = webDriver.findElement(By.xpath("//a[@class='lightblue'][@href='http://rozetka.com.ua/notebooks/c80004/filter/producer=apple;sort=expansiv/']"));
        targetElement.click();
    }

    public WebElement getMacBookZ0PU002JE()
    {
        Log4Test.info("Finding and getting AppleMacBookZ0PU002JE");
        WebElement targetBook = webDriver.findElement(By.xpath("//div[@class='gtile-i-title']/a[@href='http://rozetka.com.ua/apple_macbook_pro_retina_15_z0pu002je/p699984/']"));
        return targetBook;
    }

    public WebElement addMacBookZ0PU002JEToCompare()
    {
        if (!getMacBookZ0PU002JE().getText().contains("checked"))
        {
            Log4Test.info("AppleMacBookZ0PU002JE was not added to compare yet. Adding it now...");
            targetElement = webDriver.findElement(By.xpath("//div[@class='gtile-i-title']/a[@href='http://rozetka.com.ua/apple_macbook_pro_retina_15_z0pu002je/p699984/']/../..//input[@class='g-tools-to-compare-check']"));
            targetElement.click();

        }
        return webDriver.findElement(By.xpath("//*[@class='list-compare']/*/*[@class='block']"));
    }

    public WebElement getMacBookME294UAA()
    {
        Log4Test.info("Finding and getting AppleMacBookME294UAA");
        WebElement targetBook = webDriver.findElement(By.xpath("//div[@class='gtile-i-title']/a[@href='http://rozetka.com.ua/apple_macbook_pro_retina_15_me294ua_a/p338650/']"));
        return targetBook;
    }

    public WebElement addMacBookME294UAAToCompare()
    {
        if (!getMacBookME294UAA().getText().contains("checked"))
        {
            Log4Test.info("AppleMacBookME294UAA was not added to compare yet. Adding it now...");
            targetElement = webDriver.findElement(By.xpath("//div[@class='gtile-i-title']/a[@href='http://rozetka.com.ua/apple_macbook_pro_retina_15_me294ua_a/p338650/']/../..//input[@class='g-tools-to-compare-check']"));
            targetElement.click();

        }
        return webDriver.findElement(By.xpath("//*[@class='list-compare']/*/*[@class='block']"));
       // WebDriverWait waiting = new WebDriverWait(webDriver,50);
       // WebElement linkAppeared = waiting.until(ExpectedConditions.visibilityOf(webDriver.findElement(By.xpath(".//*[@id='comparison62824']/div/div/div/ul/li[1]"))));
        //return linkAppeared;
    }

    public String GetTextFromVerificationList()
    {
        //WebDriverWait waiting = new WebDriverWait(webDriver,50);
        targetElement = webDriver.findElement(By.xpath("//*[@class='list-compare']/*/*[@class='block']"));
        //targetElement = waiting.until(ExpectedConditions.visibilityOf(webDriver.findElement(By.xpath("//*[@class='list-compare']/*/*[@class='block']"))));
        webDriver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
        Log4Test.info("The blocktext is ... "+ targetElement.getText().toString());


        return targetElement.getText().toString();
    }

    public void ClickInCompareOnME294UAA()
    {
        targetElement = webDriver.findElement(By.xpath("//div[@class='gtile-i-title']/a[@href='http://rozetka.com.ua/apple_macbook_pro_retina_15_me294ua_a/p338650/']/../..//a[@class='lightblue underline']"));//(".//*[@id='block_with_goods']/div[1]/div[1]/div[6]/div[1]/div/div/div[4]/div[1]/span/a"));
        targetElement.click();
        Log4Test.info("Clicking В сравнении on ME294UAA Apple Book...");

    }





}
